package com.hs.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.hs.sfzy.entity.ConsultantEvaluation;
import com.hs.sfzy.service.ConsultantEvaluationService;
import com.hs.sfzy.until.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName ConsultantEvaluationController
 * @Description TODO
 * @Author wangzhihao
 * @Date 2025年08月13日 15:56
 * @Version 1.0
 */
@RestController
@RequestMapping("consultantEvaluation")
public class ConsultantEvaluationController {
    @Autowired
    private ConsultantEvaluationService consultantEvaluationService;
    @PostMapping
    public R insertConsultantEvaluation(@RequestBody ConsultantEvaluation consultantEvaluation) {
        int insert = consultantEvaluationService.insert(consultantEvaluation);
        if (insert > 0) {
            return R.ok();
        }
        return R.fail();
    }
    @GetMapping("/consultantEvaluations")
    public R getConsultantEvaluation(Integer consultantId) {
       List<ConsultantEvaluation> list= consultantEvaluationService.getconsultantEvaluations(consultantId);
return R.ok(list);
    }


    @GetMapping("{id}")
    public R getConsultantEvaluationById(@PathVariable("id") int id) {
        ConsultantEvaluation consultantEvaluation = consultantEvaluationService.selectById(id);
        return R.ok(consultantEvaluation);
    }
    @GetMapping("page")
    public R getConsultantEvaluationByPage(@RequestParam(required = false,defaultValue = "1") int pageNum,
                                           @RequestParam(required = false,defaultValue = "5") int pageSize) {
        PageInfo<ConsultantEvaluation> consultantEvaluationPageInfo = consultantEvaluationService.selectAll(pageNum, pageSize);
        return R.ok(consultantEvaluationPageInfo);
    }
    @GetMapping("user/{id}")
    public R getConsultantEvaluationByUserId(@PathVariable("id") int id) {
        PageInfo<ConsultantEvaluation> consultantEvaluationPageInfo = consultantEvaluationService.selectUser(id);
        return R.ok(consultantEvaluationPageInfo);
    }
    @GetMapping("like")
    public R getConsultantEvaluation(ConsultantEvaluation consultantEvaluation,Integer pageNum,Integer pageSize) {
        PageInfo<ConsultantEvaluation> consultantEvaluations = consultantEvaluationService.selectLike(consultantEvaluation, pageNum, pageSize);
        return R.ok(consultantEvaluations);
    }

    @PutMapping
    public R updateConsultantEvaluation(@RequestBody ConsultantEvaluation consultantEvaluation) {
        int update = consultantEvaluationService.update(consultantEvaluation);
        if (update > 0) {
            return R.ok();
        }
        return R.fail();
    }

}
